﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Peekaboo2008.dao;
using Peekaboo2008.model;

namespace Peekaboo2008.view
{
    public partial class FormNganhHang : Form
    {
        public FormNganhHang()
        {
            InitializeComponent();
            FormNganhHangLoad();
        }

        public void FormNganhHangLoad()
        {
            DataTable dt = NganhHangDAO.getAll();
            dgvNganhHang.DataSource = dt;
        }

        private void dgvNganhHang_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormNganhHang formNganhHang = this;
            NganhHangModel model = new NganhHangModel();
            model.Id = dgvNganhHang.CurrentRow.Cells[0].Value.ToString();
            model.Ten = dgvNganhHang.CurrentRow.Cells["Ten"].Value.ToString();
            model.GhiChu = dgvNganhHang.CurrentRow.Cells["ghiChu"].Value.ToString();
            FormChiTietNganhHang formChiTietNH = new FormChiTietNganhHang(model, ref formNganhHang);
            formChiTietNH.ShowDialog();
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormNganhHang formNganhHang = this;
            FormChiTietNganhHang formChiTietNH = new FormChiTietNganhHang(ref formNganhHang);
            formChiTietNH.ShowDialog();
        }

        private void FormNganhHang_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormNganhHang_KeyDown);
        }

        private void FormNganhHang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
